package user_inter_mid

import (
	"context"
	"fmt"
	"selfService/tool"
	"selfService/兴趣相关/dao"
	"selfService/兴趣相关/models"
	"time"
)

type UserInterestService struct {}


// 得到个人的兴趣选项
func (this *UserInterestService)GetInterestSelf(c context.Context, u *UserInterMidRquest) (*User_InterMidList, error)  {
	interest_Mind_dao := &dao.UserInterMidDao{}
	Interest_colloct_dao := &dao.Interest_colloct_dao{}
	result := []*User_InterMid{}
	for _,i := range *interest_Mind_dao.GetInterestById(u.Id){
		TheInterests := Interest_colloct_dao.GetInterestById(i.Inter_id)
		result = append(result, &User_InterMid{
			Id: i.Id,
			KeepField1: i.Keep_field1,
			KeepField2: i.Keep_field2,
			UserId: i.Id,
			InterId: i.Inter_id,
			IntereName: TheInterests.Interest_name,
		})
	}
	fmt.Println("输出结果")
	fmt.Println(result)

	return &User_InterMidList{
		Intrslist:result,
		Listlen: int32(len(result)),
	},nil

}


//根据id修改兴趣选项
func (this *UserInterestService)ChangeSelfInterestById(c context.Context,request *ChangeInterestRequest) (*ChangeInterestResponse, error)  {
	interest_Mind_dao := &dao.UserInterMidDao{}
	result := interest_Mind_dao.ChangeInterest(request.Id,request.Changeid)
	return &ChangeInterestResponse{
		State: result,
	},nil
}

// 根据id 删除自己某个选项
func (this *UserInterestService)DeleteSelfInterestById(c context.Context, re *UserInterMidRquest) (*ChangeInterestResponse, error)  {
	interest_Mind_dao := &dao.UserInterMidDao{}
	result := interest_Mind_dao.DeleteSelfInterest(re.Id)
	x := ""
	if result==true {
		x = "成功"
	}else {
		x = "失败"
	}
	return &ChangeInterestResponse{
		State: x,
	},nil
}

// 添加兴趣
func (this *UserInterestService)InsertSelfInterest(c context.Context,i *Interest) (*InterestReponse, error)  {
	mod := &models.User_inter_mid{};
	mod.CreateTime = time.Now()
	mod.UpdateTime = time.Now()
	mod.Id = tool.GenerateID()
	mod.User_id = i.UserId
	mod.Inter_id = i.InterestId

	interest_colloct_dao := &dao.UserInterMidDao{}
	result := interest_colloct_dao.Insert(mod)
	return &InterestReponse{
		Result: result,
	},nil
}